//
//  UIColor++.swift
//  W_BAR_MAIN
//
//  Created by LC_WJH on 2017/11/9.
//  Copyright © 2017年 LC_WJH. All rights reserved.
//

import UIKit

extension UIColor
{
    
    /// 尝试从RGB字符串(不包含0x中解析出UIColor,失败返回white)
    ///
    /// - Parameter rgbs: ffffff
    /// - Returns:
    public static func setByRGBString(_ rgbs:String)->UIColor{
        
        
        let nrgbs =  rgbs as NSString;
        if nrgbs.length == 6 {
         
            let r =  nrgbs.substring(with: NSMakeRange(0, 2));
            let g =  nrgbs.substring(with: NSMakeRange(2, 2));
            let b =  nrgbs.substring(with: NSMakeRange(4, 2));
            
            
            var ri:CUnsignedInt = 0, gi:CUnsignedInt = 0, bi:CUnsignedInt = 0;
            Scanner(string: r).scanHexInt32(&ri)
            Scanner(string: g).scanHexInt32(&gi)
            Scanner(string: b).scanHexInt32(&bi)
            
         
            
            return UITool.UIColorRGB(r: CGFloat(ri), g: CGFloat(gi), b: CGFloat(bi));
        }
        return UIColor.white;
    }
}
